//
//  GameLayer.m
//  TestFistGame
//
//  Created by  on 5/17/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "GameLayer.h"
#import "iCoreGUIController.h"

@implementation GameLayer

@synthesize listGameObject,mainGUIController;

-(id)initGameLayerWith:(iCoreGUIController *)_mainGUIController {
    self = [super init];
    
    mainGUIController = _mainGUIController;
    listGameObject = [[NSMutableArray alloc]init];
    
    [self scheduleUpdate];
    return self;
}

-(void)update:(ccTime)timeUpdate {
    //NSLog(@"time update: %f", timeUpdate);
    for(int gameObjectIndex = 0; gameObjectIndex < listGameObject.count; gameObjectIndex++) {
        [[listGameObject objectAtIndex:gameObjectIndex] update:timeUpdate];
    }
}

-(void)addGameObject:(GameObject *)_gameObject {
    [listGameObject addObject:_gameObject];
}

-(void)removeGameObject:(GameObject *)_gameObject {
    [listGameObject removeObject:_gameObject];
    
    NSLog(@"object retain count = %d", _gameObject.retainCount);
    [_gameObject stopAllActions];
    [_gameObject removeAllChildrenWithCleanup:YES];
    [_gameObject removeFromParentAndCleanup:YES];
    [_gameObject release];
}

-(void)pauseGame {
    [mainGUIController pauseGameWithCurrentLayer:self];
}

-(void)resumeGame {
    //self.isTouchEnabled = !self.isTouchEnabled;
    //[mainGUIController resumeGame:self];
}

-(void) isTouchEnableForAllChild:(BOOL)_value {
    for(id child in self.children) {
        if([child isKindOfClass:[CCMenu class]])
            [child setIsTouchEnabled:_value];
    }
}

-(void)dealloc {
    for(int i = 0; i < listGameObject.count; i++) {
        [[listGameObject objectAtIndex:i] release];
    }
    
    [super dealloc];
}

@end
